package com.qf.controller;

import com.qf.entity.SysOrder;
import com.qf.service.SysOrderService;
import com.qf.util.AliyunOSSConstants;
import com.qf.util.R;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Random;

/**
 * --- 冲 ---
 *
 * @author Biggen
 * @date 2025/4/27
 * @desc
 */
@RestController
@CrossOrigin
@RequestMapping("/zf2")
public class SysOrderController {
    private Logger logger = LogManager.getLogger(SysOrderController.class);

    @Autowired
    private SysOrderService service;

    @GetMapping("/sys/order/delete/{id}")
    public R SysOrderDelete(@PathVariable("id") int id){
        boolean okk = service.SysOrderDelete(id);
        return R.ok(okk);
    }

    @GetMapping("/sys/order/delete/all")
    public R SysOrderDeleteAll(@RequestParam("ids") List<Integer> ids){
        boolean okk = service.SysOrderDeleteAll(ids);
        return R.ok(okk);
    }

    @PostMapping("/sys/order/update")
    public R SysOrderUpdate(@RequestBody SysOrder sysOrder){
        boolean okk = service.SysOrderUpdate(sysOrder);
        return R.ok(okk);
    }

    @PostMapping("/sys/order/add")
    public R SysOrderAdd(@RequestBody SysOrder sysOrder){
        boolean okk = service.SysOrderAdd(sysOrder);
        // todo 上传图片需要orderId, 这里需要修改
        return okk ? R.ok(sysOrder) : R.fail();
    }

    @PostMapping("/sys/order/img/upload")
    public R SysOrderImgUpload(@RequestParam("file") MultipartFile file , @RequestParam("orderId") String orderId){
        String imgUrl = service.SysOrderImgUpload(file, orderId);
        return R.ok(imgUrl);
    }


    @PostMapping("/sys/order/img/upload2")
    public R SysOrderImgUpload2(@RequestParam("file") MultipartFile file , @RequestParam("orderId") String orderId){
        String imgUrl = service.SysOrderImgUpload2(file, orderId);
        return R.ok(imgUrl);
    }


}















